// pages/register/register.js
import {
    request
} from '../../request/request.js'
Page({
    data: {
        "roleId": 2,
        "account": "",
        "password": ""
    },
    onLoad(options) {

    },
    getAccount(e) {
        console.log("Account:" + e.detail.value)
        this.setData({
            account: e.detail.value
        })
    },
    getPwd(e) {
        console.log("Pwd:" + e.detail.value)
        this.setData({
            password: e.detail.value
        })
    },
    register() {

        console.log('tapRegister')
        request({
            url: "/user/insert",
            method: "POST",
            data: {
                "roleId": this.data.roleId,
                "account": this.data.account,
                "password": this.data.password
            }
        }).then(res => {
            if (res.data.code == 400) {
                wx.showToast({
                    title: res.data.msg,
                    icon:"error"
                })
            } else {
                console.log(res.data.data)
                wx.showToast({
                    title: res.data.data,
                    duration:1000,
                    success(){
                        setTimeout(() => {
                            wx.navigateBack()
                        }, 1000);
                        
                    }
                })
            }
        })
    }
})